package cn.fenqing168.springcloud.service.impl;

import cn.fenqing168.springcloud.dao.AccountDao;
import cn.fenqing168.springcloud.service.IAccountService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * 账户服务实现
 * @author fenqing
 */
@Service
@Slf4j
public class AccountServiceImpl implements IAccountService {

    @Autowired
    private Dao dao;

    @Component
    class Dao{
        @Autowired
        private AccountDao accountDao;
    }

    @SneakyThrows
    @Override
    public void decrease(Long userId, BigDecimal money) {
        log.info("开始减少账户:{}，减少余额:{}", userId, money);
        TimeUnit.SECONDS.sleep(20);
        dao.accountDao.decrease(userId, money);
        log.info("减少账户:{}完毕，减少余额:{}", userId, money);
    }
}
